﻿
using System;
namespace RakutenCrawler.Repository
{
    public class LinkRepository : GenericRepository<Link>
    {
        public override void InsertOrUpdate(Link item)
        {
            var check = Single(l => l.Url == item.Url || l.LinkId == item.LinkId);
            if (check == null)
            {

                item.InsertedDate = DateTime.Now;
                All.AddObject(item);
            }
            else
            {                
                if (item.LinkId == 0)
                {
                    item.LinkId = check.LinkId;
                    item.InsertedDate = check.InsertedDate;
                }

                All.ApplyCurrentValues(item);
            }
        }
    }
}
